package cn.beforedark.yygh.hosp.controller.api;


import cn.beforedark.yygh.common.result.R;
import cn.beforedark.yygh.hosp.service.HospitalService;
import cn.beforedark.yygh.hosp.service.HospitalSetService;
import cn.beforedark.yygh.model.hosp.Hospital;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 医院相关
 */
@RestController
@RequestMapping("/api/hosp")
public class ApiHospitalController {


    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private HospitalSetService hospitalSetService;



    /**
     * 查询医院
     *
     * @param request request
     * @return vo
     */
    @PostMapping("/hospital/show")
    public R getHospitalInfo(HttpServletRequest request) {
        Map<String, Object> map = hospitalSetService.check(request);

        String hoscode = (String) map.get("hoscode");
        Hospital hospital = hospitalService.getByHoscode(hoscode);
        return R.ok200Data(hospital);
    }


    /**
     * 上传医院
     *
     * @param request request
     * @return vo
     */
    @PostMapping("/saveHospital")
    public R saveHospital(HttpServletRequest request) {
        Map<String, Object> map = hospitalSetService.check(request);
        // 改变 传输过程中 + 变空格问题
        String logoData = (String) map.get("logoData");
        String s = logoData.replaceAll(" ", "+");
        map.put("logoData", s);

        hospitalService.save(map);

        return R.ok200();
    }




}
